package com.example.controll;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.exception.R;
import com.example.domain.Supplier;
import com.example.service.commodityServiceI;
import com.example.service.supServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    commodityServiceI commodityService;

    @Autowired
    supServiceI supplierService;

    @GetMapping
    private R getAll(){
        LambdaQueryWrapper<Supplier> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        List<Supplier> supplierList=supplierService.list(lambdaQueryWrapper);
        return R.success(supplierList);
    }

    @GetMapping("/{id}")
    private R getById(@PathVariable Long id){
        Supplier supplier=supplierService.getById(id);
        return R.success(supplier);
    }

    @PostMapping
    private R addSupplier(@RequestBody Supplier supplier){
        supplierService.save(supplier);
        return R.success("添加成功");
    }

    @DeleteMapping("/{id}")
    private R deleteById(@PathVariable Long id){
        supplierService.removeById(id);
        return R.success("删除成功");
    }

}

